var t = getApp();

Page({
    data: {
        show: !1,
        page_type: "",
        get_url: "",
        order_by: "new",
        province_list: [],
        city_list: [],
        title_word: "最新案例",
        list: [],
        province_id: "",
        city_id: "",
        province_text: "",
        area_text: "",
        city_text: "",
        page: 1
    },
    onLoad: function(t) {
        t.name && this.setData({
            page_type: t.name
        }), this.initData(), this._initAddressInfo();
    },
    initData: function() {
        console.log("123232332");
        this.data.city_list = [], this.data.province_id = "", this.data.city_id = "", this.data.province_text = "", 
        this.data.city_text = "", this.setData({
            show: !1,
            title_word: "最新案例",
            order_by: "new",
            list: [],
            page: 1
        }), "caseLibraryAreaMobile" == this.data.page_type ? (this.setData({
            get_url: t.getNetAddresss("plugin.case-library.api.mobile.home.region-case")
        }), this.getList("area", "area")) : (this.setData({
            get_url: t.getNetAddresss("plugin.case-library.api.mobile.home.new-case-list")
        }), this.getList("new", this.data.order_by));
    },
    openArea: function() {
        this.setData({
            show: !this.data.show
        });
    },
    getListOne: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.fir, e = t.currentTarget.dataset.two;
        this.setData({
            page: 1,
            list: []
        }), this.getList(a, e);
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), this.getMoreData();
        }
    },
    onShareAppMessage: function() {},
    getMoreData: function() {
        var a = this, e = [];
        e = "caseLibraryAreaMobile" == a.data.page_type ? {
            province_id: a.data.province_id,
            city_id: a.data.city_id,
            page: a.data.page
        } : {
            order_by: a.data.order_by,
            page: a.data.page
        }, t._postNetWork({
            url: a.data.get_url,
            data: e,
            success: function(t) {
                var e = t.data;
                if (1 == e.result) {
                    var i = e.data.case.data;
                    a.setData({
                        list: a.data.list.concat(i),
                        current_page: e.data.case.current_page,
                        last_page: e.data.case.last_page
                    });
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getList: function(a, e) {
        var i = this;
        console.log(a, e, "sadddd"), e && (i.setData({
            order_by: e
        }), "new" == i.data.order_by ? i.setData({
            title_word: "最新案例"
        }) : "hot" == i.data.order_by ? i.setData({
            title_word: "热门案例"
        }) : "area" == i.data.order_by && i.setData({
            title_word: "区域案例"
        }));
        var s = {};
        "new" == a ? s = {
            order_by: i.data.order_by
        } : "area" == a && (i.setData({
            title_word: "区域案例"
        }), s = {
            province_id: i.data.province_id || "",
            city_id: i.data.city_id || ""
        }), t._postNetWork({
            url: i.data.get_url,
            data: s,
            success: function(t) {
                var e = t.data;
                1 == e.result ? (i.list = [], i.setData({
                    list: e.data.case.data,
                    current_page: e.data.case.current_page,
                    last_page: e.data.case.last_page
                }), "area" == a && i.setData({
                    show: !1
                })) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onClose: function() {
        this.setData({
            show: !1
        });
    },
    changePro: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            provinceName: t.currentTarget.dataset.item.areaname
        }), this._getCityData(a);
    },
    changeCity: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.item.parentid, e = t.currentTarget.dataset.item.id, i = t.currentTarget.dataset.item.areaname;
        this.setData({
            province_id: a,
            city_id: e,
            cityName: i,
            area_text: "".concat(this.data.provinceName).concat(i)
        }), this.getList("area", "area");
    },
    _initAddressInfo: function() {
        var a = this;
        wx.getStorage({
            key: "provinceData",
            success: function(t) {
                console.log("地址信息准备就绪"), console.log(t), a._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), t._getNetWork({
                    url: t.getNetAddresss("member.member-address.address"),
                    success: function(t) {
                        var e = t.data, i = e.data.province, s = e.data.city, o = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: i
                        }), wx.setStorage({
                            key: "cityData",
                            data: s
                        }), wx.setStorage({
                            key: "districtData",
                            data: o
                        }), a._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    province_list: a.data
                });
            }
        });
    },
    _getCityData: function(t) {
        var a = t.id, e = this;
        wx.getStorage({
            key: "cityData",
            success: function(t) {
                console.log("城市读取成功", t.data), console.log(a);
                for (var i = [], s = 0; s < t.data.length; s++) t.data[s].parentid == a && i.push(t.data[s]);
                console.log("城市数据筛选", i), e.setData({
                    city_list: i
                });
            }
        });
    }
});